package auto;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

public class Smena1Panel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5026847500375844829L;

	private JLabel labelIme;
	private JButton dugmePocni = null;
	private JButton dugmeZakljuci = null;
	private JButton dugmeKomentar = null;

	GridBagLayout gbl = new GridBagLayout();
	GridBagConstraints gbc = new GridBagConstraints();

	public Smena1Panel() {
		TitledBorder titledBorder = BorderFactory.createTitledBorder("Smena 1");
		setBorder(titledBorder);
		setLayout(gbl);

		add(getLabelIme());
		add(getPocniDugme());
		add(getKomentarDugme());
		add(getZakljuciDugme());
	}

	// ********************************************** geter za labelu ime i
	// prezime ulogovanog radnika
	private JLabel getLabelIme() {
		labelIme = new JLabel("Ime_Prezime");
		// !!!!!!!!!!
		gbcXY(0, 0);
		gbc.anchor = GridBagConstraints.NORTH;
		gbc.weighty = 2;
		gbl.setConstraints(labelIme, gbc);

		return labelIme;
	}

	public void setLabelIme(String imePrezime) {
		labelIme.setText(imePrezime);

	}

	// private JLabel getLabel1(){
	//
	//
	//
	// }

	// ********************************************** geter za Pocni dugme
	Smena1Panel s1 = this;

	private JButton getPocniDugme() {
		if (dugmePocni == null) {
			dugmePocni = new JButton();
			dugmePocni.setIcon(loadIcon("/icons/add.png"));
			gbcXY(0, 1);
			gbc.weighty = 1;
			gbl.setConstraints(dugmePocni, gbc);
			dugmePocni.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					LogIn lg = new LogIn(s1, null);
					lg.setVisible(true);
					lg.setAlwaysOnTop(true);

					Var.smenalog = 1;

				}
			});

		}
		return dugmePocni;

	}

	private JButton getKomentarDugme() {
		if (dugmeKomentar == null) {
			dugmeKomentar = new JButton();
			dugmeKomentar.setIcon(loadIcon("/icons/comment.png"));
			gbcXY(0, 2);
			gbc.weighty = 1;
			gbl.setConstraints(dugmeKomentar, gbc);
		}
		return dugmeKomentar;

	}

	// ********************************************** geter za Zakljuci dugme
	private JButton getZakljuciDugme() {
		if (dugmeZakljuci == null) {
			dugmeZakljuci = new JButton();
			dugmeZakljuci.setIcon(loadIcon("/icons/remove.png"));
			gbcXY(0, 3);
			gbc.weighty = 1;
			gbl.setConstraints(dugmeZakljuci, gbc);

		}
		return dugmeZakljuci;

	}

	public void gbcXY(int x, int y) {
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.insets = new Insets(10, 10, 10, 10);
	}

	public ImageIcon loadIcon(String path) {
		return new ImageIcon(getClass().getResource(path));
	}

}
